#!/bin/bash

#------------------Create Data------------------
echo "
#par degree             MPI         Sandy Bridge      Baseline CUDA   OptimisedCUDA     Edgecon Split       Vflux Split       Iflux Split
2                       223236.328  171601.0350       128799.40300    120178.909482667  90451.4464268333    80758.7560948333  67541.78381
4                       88744.7930  78197.33045       128799.40300    120178.909482667  90451.4464268333    80758.7560948333  67541.78381
6                       59021.6619  -                 128799.40300    120178.909482667  90451.4464268333    80758.7560948333  67541.78381
8                       49312.5003  -                 128799.40300    120178.909482667  90451.4464268333    80758.7560948333  67541.78381
12                      40266.336   -                 128799.40300    120178.909482667  90451.4464268333    80758.7560948333  67541.78381
"> data1


#--------------------------Plot Data----------------------------

gnuplot <<END

set term epslatex color
set grid xtics ytics mxtics mytics    
set size 1,0.85
#set format "$%g$"


#set format xy "2^{%b}"
set format xy "$%g$"

set xlabel "Number of cores (1 MPI process per core)" 
set ylabel "Execution time (mili-seconds)" 3,1

set datafile missing '-'


#set xrange [50:21000]
set yrange [0:240000]

set style line 1 lt -1 lw 0.3
set key width 0
set key box linestyle 1 right top


#set log x 2
#set log y 2
set border lw 2

set output "./Fig.tex"

plot "data1" u 1:2 with linespoints title "MPI (westmere)"      lt 1 pt 8  linecolor rgb '#DD0000' lw 6 ps 1.5, \
"data1" u 1:3 with linespoints title "MPI (sandy bridge)"      lt 1 pt 7  linecolor rgb '#6B8E23' lw 6 ps 1.5, \
"data1" u 1:4 with lines title "CUDA-Baseline"      lt 2  linecolor rgb '#000044' lw 8, \
"data1" u 1:8 with lines title "CUDA-Optimized"      lt 1  linecolor rgb '#0000AA' lw 8;

#plot "data1" u 1:2 with linespoints title "OPlus MPI"      lt 1 pt 8  linecolor rgb '#880000' lw 3 ps 1.5, \
#"data1" u 1:3 with lines title "CUDA-Baseline"      lt 2  linecolor rgb '#0000CC' lw 6, \
#"data1" u 1:6 with lines title "CUDA-Optimized"      lt 1  linecolor rgb '#0000AA' lw 6;


END



epstopdf Fig.eps

#-----------------------------------------
echo " \documentclass{article}
\usepackage{graphics}
\usepackage{nopageno}
%\usepackage{mathpazo}
\usepackage{txfonts}
\usepackage[usenames]{color}
	
\begin{document}
	
\begin{center}
  \small{
  \input{./Fig.tex}}
\end{center}
	
\end{document}" > Figure.tex
#-----------------------------------------

pdflatex Figure.tex
pdfcrop Figure.pdf

mv Figure-crop.pdf Scalability.pdf

rm -f data* Figure.tex Figure.pdf Figure.log Figure.aux Figure.log Fig.eps Fig.tex Fig.pdf *~
evince Scalability.pdf &
